package com.pay.util;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;

/**
 * http请求客户端
 */
public class H5HttpClientUtils {

	public static JSONObject doGet(String url) throws IOException {
		JSONObject jSONObject = null;
		CloseableHttpClient client =HttpClients.createDefault();

		HttpGet httpGet = new HttpGet(url);
		HttpResponse response = client.execute(httpGet);
		HttpEntity entity = response.getEntity();
		if (entity!=null){
			String result = EntityUtils.toString(entity,"UTF-8");
			jSONObject = JSONObject.parseObject(result);
		}
		httpGet.releaseConnection();
		return jSONObject;
	}
}
